home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / tsipp / tsipp.lha / tsipp3.0a / src / tSippPPM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-02  |  3.4 KB  |  97 lines

  1. /*
  2.  *=============================================================================
  3.  *                                  tSippPPM.c
  4.  *-----------------------------------------------------------------------------
  5.  * Tcl commands to do SIPP rendering to PPM and PBM files.
  6.  *-----------------------------------------------------------------------------
  7.  * Copyright 1992 Mark Diekhans
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies.  Mark Diekhans makes
  11.  * no representations about the suitability of this software for any purpose.
  12.  * It is provided "as is" without express or implied warranty.
  13.  *-----------------------------------------------------------------------------
  14.  * $Id: tSippPPM.c,v 2.0 1992/11/02 03:56:28 markd Rel $
  15.  *=============================================================================
  16.  */
  17.  
  18. #include "tSippInt.h"
  19.  
  20. /*=============================================================================
  21.  * SippPPMRender --
  22.  *   Implements the command:
  23.  *     SippPPMRender fileid xsize ysize [mode] [oversample]
  24.  * Note:
  25.  *   This procedure has standard Tcl command calling sematics.  ClientData
  26.  * contains a pointer to the Tcl SIPP global structure.
  27.  *-----------------------------------------------------------------------------
  28.  */
  29. static int
  30. SippPPMRender (clientData, interp, argc, argv)
  31.     char       *clientData;
  32.     Tcl_Interp *interp;
  33.     int         argc;
  34.     char      **argv;
  35. {
  36.     tSippGlob_pt        tSippGlobPtr = (tSippGlob_pt) clientData;
  37.     tSippRenderParms_t  renderParms;
  38.     OpenFile           *ppmFilePtr;
  39.  
  40.     if (!TSippParseRenderParms (tSippGlobPtr, argc, argv, "fileid",
  41.                                 &renderParms))
  42.         return TCL_ERROR;
  43.  
  44.     if (TclGetOpenFile (interp, renderParms. fileHandle,
  45.                         &ppmFilePtr) != TCL_OK)
  46.          return TCL_ERROR;
  47.  
  48.     if (!ppmFilePtr->writable) {
  49.         Tcl_AppendResult (interp, "Output file is not open for writting",
  50.                           (char *) NULL);
  51.         return TCL_ERROR;
  52.     }
  53.  
  54.     /*
  55.      * Make sure rendering is in the correct order.
  56.      */
  57.     sipp_render_direction (FALSE);
  58.  
  59.     if (renderParms.interlaced)
  60.         render_field_file (renderParms.xSize,
  61.                            renderParms.ySize,
  62.                            ppmFilePtr->f,
  63.                            renderParms.mode,
  64.                            renderParms.overSampling,
  65.                            renderParms.field);
  66.     else
  67.         render_image_file (renderParms.xSize,
  68.                            renderParms.ySize,
  69.                            ppmFilePtr->f,
  70.                            renderParms.mode,
  71.                            renderParms.overSampling);
  72.     return TCL_OK;
  73.  
  74. } /* SippPPMRender */
  75.  
  76. /*=============================================================================
  77.  * TSippPPMInit --
  78.  *   Initialized the PPm and PBM rendering commands.
  79.  *
  80.  * Parameters:
  81.  *   o tSippGlobPtr (I) - Pointer to the top level global data structure.
  82.  *     (currently unused).
  83.  *-----------------------------------------------------------------------------
  84.  */
  85. void
  86. TSippPPMInit (tSippGlobPtr)
  87.     tSippGlob_pt    tSippGlobPtr;
  88. {
  89.     static tSippTclCmdTbl_t cmdTable [] = {
  90.         {"SippPPMRender",  SippPPMRender},
  91.         {NULL,             NULL}
  92.     };
  93.  
  94.     TSippInitCmds (tSippGlobPtr, cmdTable);
  95.  
  96. } /* TSippPPMInit */
  97.